x86/PVH: improve Dom0 memory size calculation
authorJan Beulich <jbeulich@suse.com>
Wed, 15 Dec 2021 09:19:54 +0000 (10:19 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 15 Dec 2021 09:19:54 +0000 (10:19 +0100)
commit5b226ca74bb2c5cd84ede5c1f2b859c2e3bcd8a0
tree128edb8014b636de5850a4f39d65daf0b795ed1e
parenta6d21af4a12d310fec72ca3e87e2a3b045643a25
x86/PVH: improve Dom0 memory size calculation

Assuming that the accounting for IOMMU page tables will also take care
of the P2M needs was wrong: dom0_paging_pages() can determine a far
higher value, high enough for the system to run out of memory while
setting up Dom0. Hence in the case of shared page tables the larger of
the two values needs to be used (without shared page tables the sum of
both continues to be applicable).

To not further complicate the logic, eliminate the up-to-2-iteration
loop in favor of doing a few calculations twice (before and after
calling dom0_paging_pages()). While this will lead to slightly too high
a value in "cpu_pages", it is deemed better to account a few too many
than a few too little.

As a result the calculation is now deemed good enough to no longer
warrant the warning message, which therefore gets dropped.

Also uniformly use paging_mode_enabled(), not is_hvm_domain().

While there also account for two further aspects in the PV case: With
"iommu=dom0-passthrough" no IOMMU page tables would get allocated, so
none need accounting for. And if shadow mode is to be enabled (including
only potentially, because of "pv-l1tf=dom0"), setting aside a suitable
amount for the P2M pool to get populated is also necessary (i.e. similar
to the non-shared-page-tables case of PVH).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/dom0_build.c